//
//  MyNavigationController.m
//  Ghac 4S
//
//  Created by apple on 11-8-29.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "MyNavigationController.h"
#import "Global.h"
#import "MainEntry.h"
#import "LocationController.h"
#import "NewsControler.h"
#import "PartsPriceController.h"
#import "QAController.h"
#import "PartRepairController.h"
#import "ContactController.h"
#import "MyNavigationController.h"
#import "ShopView.h"


@implementation MyNavigationController
@synthesize navigationController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
        m_viewControllerList = [[NSMutableDictionary alloc] init];
       
    }
    return self;
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIViewController* controller = [[MainEntry alloc] init];
//    [self.navigationController setDelegate:self];
    [self.navigationController pushViewController:controller animated:NO];
    [controller release];
    [UIApplication sharedApplication].keyWindow.rootViewController = self.navigationController;

    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)backToMainEntry:(id)sender
{
    
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

+(MyNavigationController *)mainNavigationController
{
    if (currentNavigationController == Nil)
    {
        currentNavigationController = [[MyNavigationController alloc] initWithNibName:@"MyNavigationController" bundle:[NSBundle mainBundle]];
        
    }
    return currentNavigationController;
}
+(void)clearInstance
{
    if(currentNavigationController != Nil)
    {
        [currentNavigationController release];
        currentNavigationController = Nil;
    }
}
-(void)changeToView:(NSString *)viewTag
{
    UIViewController* newViewController = nil;
    if ([m_viewControllerList objectForKey:viewTag] == Nil)
    {
        if ([viewTag isEqualToString:[Global BTN_L_NEWS]])
        {
            newViewController = [[NewsControler alloc] init];
            
        }
        else if ([viewTag isEqualToString:[Global BTN_L_LOCATION]])
        {
            newViewController = [[LocationController alloc] init];
            
        }
        else if ([viewTag isEqualToString:[Global BTN_L_CONTACT]])
        {
            newViewController = [[ContactController alloc] init];
        }
        else if ([viewTag isEqualToString:[Global BTN_L_PRICE]])
        {
            newViewController = [[PartsPriceController alloc] init];
        }
        else if ([viewTag isEqualToString:[Global BTN_L_QA]])
        {
            newViewController = [[QAController alloc] init];
        }
        else if ([viewTag isEqualToString:[Global BTN_L_REPAIR]])
        {
            newViewController = [[PartRepairController alloc] init];
        }
        else if ([viewTag isEqualToString:[Global SHOP_DETAIL_VIEW]])
        {
            newViewController = [[ShopView alloc] init];
        }
        [m_viewControllerList setObject:newViewController forKey:viewTag];
    }
    else
    {
        newViewController = [m_viewControllerList objectForKey:viewTag];
    }
    [navigationController pushViewController:newViewController animated:YES];
    
}

@end
